package com.yusys.pattern.regular.oecm.second;

import com.yusys.pattern.regular.oecm.IBook;

import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;

public class BookStore {
    private  static final List<IBook> bookList = new ArrayList<IBook>();

    //只需要在此处将小说类替换成小说折扣类 就可以实现功能的扩展
    static {
        bookList.add(new NovelOffPrice("天龙八部",3200,"金庸"));
        bookList.add(new NovelOffPrice("巴黎圣母院",5600,"雨果"));
        bookList.add(new NovelOffPrice("悲惨世界",3500,"雨果"));
        bookList.add(new NovelOffPrice("金瓶梅",4300,"兰陵笑笑生"));
    }

    public static void main(String[] args) {
        NumberFormat format = NumberFormat.getCurrencyInstance();
        format.setMaximumFractionDigits(2);//精确位数

        for (int i = 0; i < bookList.size(); i++) {
            System.out.println("name:"+bookList.get(i).getName()+"\tauthor:"+bookList.get(i).getAuthor()+"\tprice:"
                    +format.format(bookList.get(i).getPrice()/100.0));//这个除数100 和100.0是有区别的
        }
    }
}
